<?php
namespace Api\Controller;
use Think\Controller;
class IndexController extends BaseController {

	public function _initialize(){
		parent::_initialize();
	
		$this->mem = M("member");
		$this->userid = (int)I('uid');
		$this->sign = I('sign');  
	}
	

	/** 2016-5-5
	* Function lbs: 更新定位
	*
	*/
        public function test(){
            $arr = M('shop_address')->select();
            $arr01 = json_encode($arr);
            print_r($arr01);exit;
        }
	
		public function lbs($mapx=null,$mapy=null,$uid=null,$city_code=null){    //通过传送定位的经度纬度
				if($mapx){
				$newdata['city']=(int)$city_code;
				$newdata['city_code']=(int)$city_code;
				$newdata['gps']=array((float)$mapx,(float)$mapy);
				$newdata['addtime']=time();
				$newdata['uid']=(int)$uid;
				$where['uid']=(int)$uid;
				$num=M_G('users')->where($where)->count();
					   $city_name=M('baidu_city')->where("city_code=".$city_code)->getField('city_name');
	                   M('member')->where("id=".$uid)->setField('city',$city_name);  //更新mysql城市标识
				if($num>0){
				M_G('users')->update($where,$newdata);
				}else{
				$newdata['status']=(int)0;
				M_G('users')->add($newdata);
				}
				}else{
				$where['uid']=(int)$uid;
				$newdata['city']=M_G('users')->where($where)->getField("city");
				$newdata['city_code']=M_G('users')->where($where)->getField("city_code");
				}
				return  true;
		}
	
		   
	/** 2016-5-5
	* Function info: 首页
	*
	*/
	
	public function info(){
		        $mapx= (float)I('mapx');//匹配经度
		        $mapy= (float)I('mapy'); //匹配经度	
				
				if(I('scity')){ //切换城市
						
					if(I('scitycode')){
					$city=I('scitycode');
					$city_code=$this->check_citycode($city);
					}else{
					$city=I('scity');
					$city_code=$this->check_ios_citycode($city);    //IOS
					}
				
				}else{
				
					if(I('citycode')){
					$city=I('citycode');
					$city_code=$this->check_citycode($city);
					}else{
					$city=I('city');
					$city_code=$this->check_ios_citycode($city);    //IOS
					}
				
				}
				
		         $this->add_everyday_jifen($this->userid);  //登录+2积分
				
				
				if($this->userid){
				$this->lbs($mapx,$mapy,$this->userid,$city_code);   //更新定位
				}
				
			    
				
				$num=10; //显示数量
	            if($city_code){  //定位信息存在

							
				$tablename="jdr_users";  //表
				$maxDistance="maxDistance:1000/6378000"; //指定范围

				$skill_list=M_G('skill')->execute("db.runCommand({geoNear:'jdr_skill', near:[$mapx,$mapy], spherical:true,num:".$num.", distanceMultiplier:6378 , query:{ city:$city_code,status:0 } })");   
		        $task_list=M_G('task')->execute("db.runCommand({geoNear:'jdr_task', near:[$mapx,$mapy], spherical:true,num:".$num.", distanceMultiplier:6378, query:{ city:$city_code,status:1,".mgSelect_or.":[{guoqi_time:0},{guoqi_time:{".mgSelect_gt.":".time()."}}]  } })");
			    //".mgSelect_or.":[{guoqi_time:0},{guoqi_time:{".mgSelect_gt.":".time()."}}]  //永久或未过期时间比对
				
				//print_r($skill_list);exit;
 
				foreach($skill_list['results'] as $key=>$item){
				$skill[$key]['dis'] = $item['dis']?(string)number_format($item['dis'],2,'.',''):"0.00";
				$skill[$key]['uid'] = $item['obj']['uid'];
				$skill[$key]['id'] = $item['obj']['id'];
				$skill[$key]['status'] =$item['obj']['status'];
				$skill[$key]['in_id'] = $item['obj']['in_id'];
				$skill[$key]['classone'] = $item['obj']['classone'];
				$skill[$key]['classpic'] = M('industry_class')->where("id=".$item['obj']['classone'])->getField('pic_path')?__VUPLOAD__.M('industry_class')->where("id=".$item['obj']['classone'])->getField('pic_path'):"";
				$skill[$key]['in_name'] = $this->ms->where("id=".$item['obj']['id'])->getField('in_name');
				$skill[$key]['nickname'] = $this->minfo->where("mid=".$item['obj']['uid'])->getField('nickname');
				$skill[$key]['sex'] = (string)$this->minfo->where("mid=".$item['obj']['uid'])->getField('sex');
		        $skill[$key]['pic'] = $this->minfo->where("mid=".$item['obj']['uid'])->getField('pic')?$this->oss_view($this->minfo->where("mid=".$item['obj']['uid'])->getField('pic')):"";
				$skill[$key]['user_id'] = (string)$item['obj']['uid'];
				$skill[$key]['age'] = $this->birthday(date('Y-m-d',$this->minfo->where("mid=".$item['obj']['uid'])->getField('stime')));
				$skill[$key]['price'] = $this->ms->where("id=".$item['obj']['id'])->getField('price');
				$skill[$key]['unit'] = $this->ms->where("id=".$item['obj']['id'])->getField('unit');
				$skill[$key]['skill_desc'] = $this->ms->where("id=".$item['obj']['id'])->getField('skill_desc');
				$skill[$key]['hx_name'] =  $this->minfo->where("mid=".$item['obj']['uid'])->getField('hx_name')?$this->minfo->where("mid=".$item['obj']['uid'])->getField('hx_name'):"";   //环信用户名
				$skill[$key]['user_type']=(string)$this->mem->where("id=".$item['obj']['uid'])->getField('type');    //用户类型 企业用户
			    $skill[$key]['morepic'] =$this->return_morepic_data($item['obj']['id'],1)[0]?$this->return_morepic_data($item['obj']['id'],1)[0]:array();   //任务图片多图
		        $skill[$key]['morepic_num'] =(string)$this->return_morepic_data($item['obj']['id'],1)[1];   //任务图片多图数
			
				}
								  
				foreach($task_list['results'] as $key=>$item){
				$task[$key]['dis'] = $item['dis']?(string)number_format($item['dis'],2,'.',''):"0.00";
				$task[$key]['uid'] = $item['obj']['uid'];
				$task[$key]['id'] = $item['obj']['id'];
				$task[$key]['status'] =$item['obj']['status'];
				$task[$key]['in_id'] = $item['obj']['in_id'];
				$task[$key]['classone'] = $item['obj']['classone'];
				$task[$key]['classpic'] = M('industry_class')->where("id=".$item['obj']['classone'])->getField('pic_path')?__VUPLOAD__.M('industry_class')->where("id=".$item['obj']['classone'])->getField('pic_path'):"";
				$task[$key]['in_name'] =  $item['obj']['in_name'];
				$task[$key]['nickname'] = $this->minfo->where("mid=".$item['obj']['uid'])->getField('nickname');
				$task[$key]['sex'] = (string)$this->minfo->where("mid=".$item['obj']['uid'])->getField('sex');
		        $task[$key]['pic'] = $this->minfo->where("mid=".$item['obj']['uid'])->getField('pic')?$this->oss_view($this->minfo->where("mid=".$item['obj']['uid'])->getField('pic')):"";
				$task[$key]['user_id'] = (string)$item['obj']['uid'];
				$task[$key]['age'] = $this->birthday(date('Y-m-d',$this->minfo->where("mid=".$item['obj']['uid'])->getField('stime')));	
				$task[$key]['price'] = $this->mt->where("id=".$item['obj']['id'])->getField('price');
				$task[$key]['unit'] = $this->mt->where("id=".$item['obj']['id'])->getField('unit');
				$task[$key]['task_desc'] = $this->mt->where("id=".$item['obj']['id'])->getField('task_desc');	
				if($item['obj']['guoqi_time']==0){
				$task[$key]['guoqi'] = '0';   //过期状态  0  1
				$task[$key]['guoqi_time'] = "永久";   //过期时间
				}else{
				$task[$key]['guoqi'] = time()>$item['obj']['guoqi_time']?'1':'0';   //过期状态  0  1
				$task[$key]['guoqi_time'] = date("Y-m-d H:i",$item['obj']['guoqi_time']);   //过期时间
				}
				$task[$key]['user_type']=(string)$this->mem->where("id=".$item['obj']['uid'])->getField('type');    //用户类型 企业用户
				
			    $task[$key]['morepic'] =$this->return_morepic_data($item['obj']['id'],2)[0]?$this->return_morepic_data($item['obj']['id'],2)[0]:array();   //任务图片多图
		        $task[$key]['morepic_num'] =(string)$this->return_morepic_data($item['obj']['id'],2)[1];   //任务图片多图数量
				}

			    }else{   //如果未获取到定位信息  
				
				//非定位达人信息
				$skill_list= $this->ms->field('id,uid,usex,price,unit,in_id,in_name,skill_desc,depth,status,clicks,addtime,classone')->where("status=0 and city=131")->order('clicks desc,addtime desc' )->limit($num)->select();			
				foreach($skill_list as $key=>$item){
				$skill[$key]['dis'] = "";
				$skill[$key]['uid'] = (string)$item['uid'];
				$skill[$key]['id'] = (string)$item['id'];
				$skill[$key]['status'] = (string)$item['status'];
				$skill[$key]['in_id'] = (string)$item['in_id'];
				$skill[$key]['classone'] = (string)$item['classone'];
				$skill[$key]['classpic'] = M('industry_class')->where("id=".$item['classone'])->getField('pic_path')?__VUPLOAD__.M('industry_class')->where("id=".$item['classone'])->getField('pic_path'):"";
				$skill[$key]['in_name'] = $item['in_name'];
				$skill[$key]['nickname'] = $this->minfo->where("mid=".$item['uid'])->getField('nickname')?$this->minfo->where("mid=".$item['uid'])->getField('nickname'):"";
				$skill[$key]['sex'] = (string)$this->minfo->where("mid=".$item['uid'])->getField('sex');
		        $skill[$key]['pic'] = $this->minfo->where("mid=".$item['uid'])->getField('pic')?$this->oss_view($this->minfo->where("mid=".$item['uid'])->getField('pic')):"";
				$skill[$key]['user_id'] = (string)$item['uid'];
				$skill[$key]['age'] = $this->birthday(date('Y-m-d',$this->minfo->where("mid=".$item['uid'])->getField('stime')));
				$skill[$key]['price'] =  $item['price']?$item['price']:"";
				$skill[$key]['unit'] = $item['unit']?$item['unit']:"";
				$skill[$key]['skill_desc'] = $item['skill_desc']?$item['skill_desc']:"";
				$skill[$key]['hx_name'] =  $this->minfo->where("mid=".$item['uid'])->getField('hx_name')?$this->minfo->where("mid=".$item['uid'])->getField('hx_name'):"";   //环信用户名
				}
				//非定位达人信息结束
				
				//非定位任务信息
				$task_list= M_S("task")->field('id,uid,usex,price,unit,in_id,in_name,task_desc,depth,status,overday,addtime,classone,guoqi_time')->where("status=1 and city=131 and ( guoqi_time>".time()." or  guoqi_time=0 ) ")->order('addtime desc' )->limit($num)->select();
				foreach($task_list as $key=>$item){
				$task[$key]['dis'] = "";
				//$task[$key]['gps'] = $item['obj']['gps'];
				$task[$key]['uid'] = (string)$item['uid'];
				$task[$key]['id'] = (string)$item['id'];
				$task[$key]['status'] =(string)$item['status'];
				$task[$key]['in_id'] = (string)$item['in_id'];
				$task[$key]['classone'] = (string)$item['classone'];
				$task[$key]['classpic'] = M('industry_class')->where("id=".$item['classone'])->getField('pic_path')?__VUPLOAD__.M('industry_class')->where("id=".$item['classone'])->getField('pic_path'):"";
				$task[$key]['in_name'] = $item['in_name'];
				$task[$key]['nickname'] = $this->minfo->where("mid=".$item['uid'])->getField('nickname')?$this->minfo->where("mid=".$item['uid'])->getField('nickname'):"";
				$task[$key]['sex'] = (string)$this->minfo->where("mid=".$item['uid'])->getField('sex');
		        $task[$key]['pic'] = $this->minfo->where("mid=".$item['uid'])->getField('pic')?$this->oss_view($this->minfo->where("mid=".$item['uid'])->getField('pic')):"";
				$task[$key]['user_id'] = (string)$item['uid'];
				$task[$key]['age'] = $this->birthday(date('Y-m-d',$this->minfo->where("mid=".$item['uid'])->getField('stime')));
				$task[$key]['price'] = $item['price']?$item['price']:"";
				$task[$key]['unit'] =  $item['unit']?$item['unit']:"";
				$task[$key]['task_desc'] =  $item['task_desc']?$item['task_desc']:"";
				
				if($item['guoqi_time']==0){
				$task[$key]['guoqi'] = '0';   //过期状态  0  1
				$task[$key]['guoqi_time'] = "永久";   //过期时间
				}else{
				$task[$key]['guoqi'] = time()>$item['guoqi_time']?'1':'0';   //过期状态  0  1
				$task[$key]['guoqi_time'] = date("Y-m-d H:i",$item['guoqi_time']);   //过期时间
				}

				}
				//非定位任务信息结束
			    }  //如果未获取到定位信息结束  
				
				
/*                $banner=M('atm')->field("pic_path,weburl,title")->where('class_id=3 and status=1 ')->order('list_order desc,id desc')->limit(10)->select(); 
                foreach($banner as $key=>$item){
				$banner[$key]['pic_path']= __VUPLOAD__.$item['pic_path'];
				}*/
				
				
				$banner=file_get_contents(__PHYSICS__.'/App/Api/Controller/banner.txt');
				
			   if($city_code){ 	
				$where['where']=array('city'=>$city_code,'status'=>0);  
				$where['where']['gps']=array('$nearSphere'=>array($mapx,$mapy));   //默认距离排序
				$totalRows = count(M_G('skill')->select($where));//查询满足要求的总记录数
				$page_skill = ceil($totalRows/10); //总页数
		
		
				$wheret['where']=array('city'=>$city_code,'status'=>1);  //任务发布
				$wheret['where']["guoqi_time|guoqi_time"]=array(mgSelect_gt=>time()); //过期或永久查询
				$wheret['where']['gps']=array('$nearSphere'=>array($mapx,$mapy));   //默认距离排序
				$totalRowst = count(M_G('task')->select($wheret));//查询满足要求的总记录数
				$page_task = ceil($totalRowst/10); //总页数
				
				}else{
				$page_skill= 1; //总页数
				
				$page_task=1; //总页数

				}
				

				$result = array(
				'result' => '0',
				'msg' => '成功',
				'banner' =>json_decode($banner,true),
				'task' =>$task?$this->string_foreach(array_values($task)):array(),
				'skill' =>$skill?$this->string_foreach(array_values($skill)):array(),
				'page_task' =>$page_task,
				'page_skill' =>$page_skill
				);

				print json_encode($result); exit;

	}
	
	
	
	
	/** 2016-8-22
	* Function info: 首页带分页
	*
	*/
	public function info_more(){
	
	            $type= I('type'); // type=1 task   2  skill
	
		        $mapx= (float)I('mapx');//匹配经度
		        $mapy= (float)I('mapy'); //匹配经度	
				
		
				if(I('scity')){ //切换城市	
					if(I('scitycode')){
					$city=I('scitycode');
					$city_code=$this->check_citycode($city);
					}else{
					$city=I('scity');
					$city_code=$this->check_ios_citycode($city);    //IOS
					}
				
				}else{
				
					if(I('citycode')){
					$city=I('citycode');
					$city_code=$this->check_citycode($city);
					}else{
					$city=I('city');
					$city_code=$this->check_ios_citycode($city);    //IOS
					}
				}
				
				//$this->writelog_name(var_export($_REQUEST,TRUE),"info_more");		
				$pageno=I('pageno')?(int)I('pageno'):2;  //第几页
				$pageCount=I('limit')?(int)I('limit'):10;  //每页显示多少条记录

           
				 
				 
	            if($city_code){  //定位信息存在

				
				if($type==2){			
				$where['where']=array('city'=>$city_code,'status'=>0);  
				$where['where']['gps']=array('$nearSphere'=>array($mapx,$mapy));   //默认距离排序
				$totalRows = count(M_G('skill')->select($where));//查询满足要求的总记录数
				$page = ceil($totalRows/$pageCount); //总页数
				$where['page']=$pageno;      //第几页
				$where['limit']=$pageCount;    //每页限制数量
				$skill_list=M_G('skill')->select($where);
				
				foreach($skill_list as $key=>$item){
				$skill[$key]['dis'] = (string)$this->mapdis($item['_id'],$mapx,$mapy,"jdr_skill");
				$skill[$key]['uid'] = (string)$item['uid'];
				$skill[$key]['id'] = (string)$item['id'];
				$skill[$key]['status'] =(string)$item['status'];
				$skill[$key]['in_id'] = (string)$item['in_id'];
				$skill[$key]['classone'] = (string)$item['classone'];
				$skill[$key]['classpic'] = M('industry_class')->where("id=".$item['classone'])->getField('pic_path')?__VUPLOAD__.M('industry_class')->where("id=".$item['classone'])->getField('pic_path'):"";
				$skill[$key]['in_name'] = $this->ms->where("id=".$item['id'])->getField('in_name');
				$skill[$key]['nickname'] = $this->minfo->where("mid=".$item['uid'])->getField('nickname');
				$skill[$key]['sex'] = (string)$this->minfo->where("mid=".$item['uid'])->getField('sex');
		        $skill[$key]['pic'] = $this->minfo->where("mid=".$item['uid'])->getField('pic')?$this->oss_view($this->minfo->where("mid=".$item['uid'])->getField('pic')):"";
				$skill[$key]['user_id'] = (string)$item['uid'];
				$skill[$key]['age'] = $this->birthday(date('Y-m-d',$this->minfo->where("mid=".$item['uid'])->getField('stime')));
				$skill[$key]['price'] = $this->ms->where("id=".$item['id'])->getField('price');
				$skill[$key]['unit'] = $this->ms->where("id=".$item['id'])->getField('unit');
				$skill[$key]['skill_desc'] = $this->ms->where("id=".$item['id'])->getField('skill_desc');
				$skill[$key]['hx_name'] =  $this->minfo->where("mid=".$item['uid'])->getField('hx_name')?$this->minfo->where("mid=".$item['uid'])->getField('hx_name'):"";   //环信用户
				$skill[$key]['morepic'] =$this->return_morepic_data($item['id'],1)[0]?$this->return_morepic_data($item['id'],1)[0]:array();   //任务图片多图
		        $skill[$key]['morepic_num'] =(string)$this->return_morepic_data($item['id'],1)[1];   //任务图片多图数
				$skill[$key]['user_type']=(string)$this->mem->where("id=".$item['uid'])->getField('type');    //用户类型 企业用户
				}
				$list=$skill;
				
				}else{
				
				$where['where']=array('city'=>$city_code,'status'=>1);  //任务发布
				$where['where']["guoqi_time|guoqi_time"]=array(mgSelect_gt=>time()); //过期或永久查询
				$where['where']['gps']=array('$nearSphere'=>array($mapx,$mapy));   //默认距离排序
			
				$totalRows = count(M_G('task')->select($where));//查询满足要求的总记录数
				$page = ceil($totalRows / $pageCount); //总页数
				$where['page']=$pageno;      //第几页
				$where['limit']=$pageCount;    //每页限制数量
				$task_list=M_G('task')->select($where);
				
				
				foreach($task_list as $key=>$item){
				$task[$key]['dis'] =  (string)$this->mapdis($item['_id'],$mapx,$mapy,"jdr_task");
				$task[$key]['uid'] = (string)$item['uid'];
				$task[$key]['id'] = (string)$item['id'];
				$task[$key]['status'] =(string)$item['status'];
				$task[$key]['in_id'] =(string)$item['in_id'];
				$task[$key]['classone'] = (string)$item['classone'];
				$task[$key]['classpic'] = M('industry_class')->where("id=".$item['classone'])->getField('pic_path')?__VUPLOAD__.M('industry_class')->where("id=".$item['classone'])->getField('pic_path'):"";
				$task[$key]['in_name'] =  $item['in_name'];
				$task[$key]['nickname'] = $this->minfo->where("mid=".$item['uid'])->getField('nickname');
				$task[$key]['sex'] = (string)$this->minfo->where("mid=".$item['uid'])->getField('sex');
		        $task[$key]['pic'] = $this->minfo->where("mid=".$item['uid'])->getField('pic')?$this->oss_view($this->minfo->where("mid=".$item['uid'])->getField('pic')):"";
				$task[$key]['user_id'] = (string)$item['uid'];
				$task[$key]['age'] = $this->birthday(date('Y-m-d',$this->minfo->where("mid=".$item['uid'])->getField('stime')));	
				$task[$key]['price'] = $this->mt->where("id=".$item['id'])->getField('price');
				$task[$key]['unit'] = $this->mt->where("id=".$item['id'])->getField('unit');
				$task[$key]['task_desc'] = $this->mt->where("id=".$item['id'])->getField('task_desc');	
				if($item['guoqi_time']==0){
				$task[$key]['guoqi'] = '0';   //过期状态  0  1
				$task[$key]['guoqi_time'] = "永久";   //过期时间
				}else{
				$task[$key]['guoqi'] = time()>$item['guoqi_time']?'1':'0';   //过期状态  0  1
				$task[$key]['guoqi_time'] = date("Y-m-d H:i",$item['guoqi_time']);   //过期时间
				}
			    $task[$key]['morepic'] =$this->return_morepic_data($item['id'],2)[0]?$this->return_morepic_data($item['id'],2)[0]:array();   //任务图片多图
		        $task[$key]['morepic_num'] =(string)$this->return_morepic_data($item['id'],2)[1];   //任务图片多图数量
				$task[$key]['user_type']=(string)$this->mem->where("id=".$item['uid'])->getField('type');    //用户类型 企业用户
				}
				$list=$task;
				}

 


			    }else{   //如果未获取到定位信息  

			    }  //如果未获取到定位信息结束  
				
				
	        	$list=array_values($list);

				
	             returnApiData_page('0','成功',$page,$list);exit;
				
				

	}
	


	
	/** 2016-4-26
	* Function info: 达人技能
	*
	*/
		public function skill(){
						$table="jdr_skill";
						$mapx= (float)I('mapx');//匹配经度
						$mapy= (float)I('mapy'); //匹配经度
						
						//$this->writelog_name(var_export($_REQUEST,TRUE),"addindex_skill");	
						
						if(I('scity')){ //切换城市	
							if(I('scitycode')){
							$city=I('scitycode');
							$city_code=$this->check_citycode($city);
							}else{
							$city=I('scity');
							$city_code=$this->check_ios_citycode($city);    //IOS
							}
						
						}else{
						
							if(I('citycode')){
							$city=I('citycode');
							$city_code=$this->check_citycode($city);
							}else{
							$city=I('city');
							$city_code=$this->check_ios_citycode($city);    //IOS
							}
						}
								
						$pageno=I('pageno')?(int)I('pageno'):1;  //第几页
						$pageCount=I('limit')?(int)I('limit'):10;  //每页显示多少条记录
						
                        $seahot=I('search'); //搜索
						$classid=I('classid')?(int)I('classid'):"";   //分类查询
						$class_depth=I('depth')?(int)I('depth'):"";   //分类级别
						$orderby=I('orderby'); //排序参数
						$sex=I('sex')?(int)I('sex'):""; 
						$age=I('age');
						$money=I('money'); 
	
	               if($city_code){  //定位信息存在			
						$where['where']=array('city'=>$city_code,'status'=>0);  
						if($orderby==1){
						$where['order']=array('price'=>(int)'1');   //价格排序 
						}else if($orderby==2){
						$where['order']=array('ustime'=>(int)"-1");  //年龄排序  
						}else{
						$where['where']['gps']=array('$nearSphere'=>array($mapx,$mapy));   //默认距离排序
						}
						
						
						
						
			
						//******分类查询
						if($classid){   
								if($class_depth==1){
								$where['where']['classone']=$classid; 
								}else{
								$classone=M('industry_class_two')->where("id=".$classid)->getField('parent_id');  //判断是不是一级
								$where['where']['classone']=(int)$classone; 
								
								$classid_arr=M('industry_class_three')->where('parent_id='.$classid)->field('id')->select();	 
									if($classid_arr){
										foreach($classid_arr as $key=>$item){
										$classid_arr2[$key]=(int)$item['id'];
										}  
									    $where['where']['in_id']=array('$in'=>$classid_arr2); 
									}else{
									    $where['where']['in_id']=$classid; 
									}
								}
						} //****分类查询
						
						$classcid=I('classcid')?(string)I('classcid'):"";   //范围查询 anroid
						if($classcid){  $where['where']['p_arr']=array('$in'=>array("$classcid"));   }
			
						$cid=I('cid')?(string)I('cid'):"";   //范围查询 ios
						if($cid){  $where['where']['p_arr']=array('$in'=>array("$cid"));   }

						//筛选条件
						if($sex==1){   $where['where']['usex']=0;       }
						if($sex==2){   $where['where']['usex']=1;       }
						if($age){    $where['where']['ustime']=$this->return_sx($age,"agem");   }
						if($money){  $where['where']['price']=$this->return_sx($money,"moneym");   }
						if($seahot){ 
						   if($seahot=="跑腿"){    $where['where']['in_name']= array('$in'=>array("派发服务","陪同服务","代接服务"));    }else{
						   $where['where']['in_name']= array('$regex'=>$seahot);
						   }
						 } //模糊查询  

						$totalRows = count(M_G('skill')->select($where));//查询满足要求的总记录数
						$page = ceil($totalRows/$pageCount); //总页数
						$where['page']=$pageno;      //第几页
						$where['limit']=$pageCount;    //每页限制数量
						$skill_list=M_G('skill')->select($where);
						
						foreach($skill_list as $key=>$item){
						$skill[$key]['dis'] = (string)$this->mapdis($item['_id'],$mapx,$mapy,$table);
						$skill[$key]['uid'] = (string)$item['uid'];
						$skill[$key]['id'] =  (string)$item['id'];
						$skill[$key]['status'] =(string)$item['status'];
						$skill[$key]['in_id'] = (string)$item['in_id'];
						$skill[$key]['classone'] = $item['classone']?(string)$item['classone']:"";
						$skill[$key]['classpic'] = M('industry_class')->where("id=".$item['classone'])->getField('pic_path')?__VUPLOAD__.M('industry_class')->where("id=".$item['classone'])->getField('pic_path'):"";
						$skill[$key]['in_name'] = $this->ms->where("id=".$item['id'])->getField('in_name');
						$skill[$key]['nickname'] = $this->minfo->where("mid=".$item['uid'])->getField('nickname')?$this->minfo->where("mid=".$item['uid'])->getField('nickname'):"";
						$skill[$key]['sex'] =(string)$this->minfo->where("mid=".$item['uid'])->getField('sex');
						$skill[$key]['pic'] = $this->minfo->where("mid=".$item['uid'])->getField('pic')?$this->oss_view($this->minfo->where("mid=".$item['uid'])->getField('pic')):"";
						$skill[$key]['user_id'] = (string)$item['uid'];
						$skill[$key]['age'] = $this->birthday(date('Y-m-d',$this->minfo->where("mid=".$item['uid'])->getField('stime')));
						$skill[$key]['price'] = $this->ms->where("id=".$item['id'])->getField('price')?$this->ms->where("id=".$item['id'])->getField('price'):"";
						$skill[$key]['unit'] = $this->ms->where("id=".$item['id'])->getField('unit')?$this->ms->where("id=".$item['id'])->getField('unit'):"";
						$skill[$key]['skill_desc'] = $this->ms->where("id=".$item['id'])->getField('skill_desc')?$this->ms->where("id=".$item['id'])->getField('skill_desc'):"";
						$skill[$key]['hx_name'] =  $this->minfo->where("mid=".$item['uid'])->getField('hx_name')?$this->minfo->where("mid=".$item['uid'])->getField('hx_name'):"";   //环信用户
						$skill[$key]['user_type']=(string)$this->mem->where("id=".$item['uid'])->getField('type');    //用户类型 企业用户
						}
				}else{
						if($orderby==2){
						$whereorder='ustime desc,addtime desc';  //年龄排序 
						}else if($orderby==1){
						$whereorder='price asc,addtime desc';    //价格排序 
						}else{
						$whereorder='addtime desc';  ////默认排序
						}

						$where['status']=0; 
						$where['city']=131;					
						//*****分类查询
						if($classid){   			 	 
						if($class_depth==1){
						$where['classone']=$classid; 
						}else{
								$classone=M('industry_class_two')->where("id=".$classid)->getField('parent_id');  //判断是不是一级
								$where['classone']=(int)$classone; 
						$classid_arr=M('industry_class_three')->where('parent_id='.$classid)->field('id')->select();
						if($classid_arr){
						foreach($classid_arr as $key=>$item){
						$classid_arr2[$key]=(int)$item['id'];
						}  
						$where[]="in_id in(".implode(",",$classid_arr2).")"; 
						}else{
						$where['in_id']=$classid;  
						}
						}
						} 
						//****分类查询
						if($sex==1){   $where['usex']=0;       }
						if($sex==2){   $where['usex']=1;       }					
						if($age){    $where[]=$this->return_sx($age,"age");   }
						if($money){  $where[]=$this->return_sx($money,"money");   }
						if($seahot){ 
						if($seahot=="跑腿"){    $where[]= " in_name in('公共交通','私家车','非机动车')";    }else{
						$where['in_name']=array('like','%'.$seahot.'%'); 
						}
						} 					
$skill_list= $this->ms->field('id,uid,price,unit,in_id,in_name,skill_desc,depth,status,clicks,addtime,classone,usex')->where($where)->order($whereorder)->page($pageno.','.$pageCount)->select();				
						//echo   $this->ms->Getlastsql();exit;
						foreach($skill_list as $key=>$item){
						$skill[$key]['dis'] = "";
						$skill[$key]['uid'] = (string)$item['uid'];
						$skill[$key]['id'] = (string)$item['id'];
						$skill[$key]['status'] =(string)$item['status'];
						$skill[$key]['in_id'] = (string)$item['in_id'];
						$skill[$key]['classone'] = $item['classone']?(string)$item['classone']:"";
						$skill[$key]['classpic'] = M('industry_class')->where("id=".$item['classone'])->getField('pic_path')?__VUPLOAD__.M('industry_class')->where("id=".$item['classone'])->getField('pic_path'):"";
						$skill[$key]['in_name'] = $item['in_name'];
						$skill[$key]['nickname'] = $this->minfo->where("mid=".$item['uid'])->getField('nickname')?$this->minfo->where("mid=".$item['uid'])->getField('nickname'):"";
						$skill[$key]['sex'] =(string)$this->minfo->where("mid=".$item['uid'])->getField('sex');
						$skill[$key]['pic'] = $this->minfo->where("mid=".$item['uid'])->getField('pic')?$this->oss_view($this->minfo->where("mid=".$item['uid'])->getField('pic')):"";
						$skill[$key]['user_id'] = (string)$item['uid'];
						$skill[$key]['age'] = $this->birthday(date('Y-m-d',$this->minfo->where("mid=".$item['uid'])->getField('stime')));
						$skill[$key]['price'] =  $item['price']?$item['price']:"";
						$skill[$key]['unit'] = $item['unit']?$item['unit']:"";
						$skill[$key]['skill_desc'] = $item['skill_desc']?$item['skill_desc']:"";
						$skill[$key]['hx_name'] =  $this->minfo->where("mid=".$item['uid'])->getField('hx_name')?$this->minfo->where("mid=".$item['uid'])->getField('hx_name'):"";   //环信用户
						}
						$totalRows = $this->ms->where($where)->count();//查询满足要求的总记录数
						$page = ceil($totalRows / $pageCount); //总页数
				}

				$skill=array_values($skill);
	            returnApiData_page('0','成功',$page,$skill);exit;
	}
	
	/** 2016-4-26
	* Function info: 达人技能详情
	*
	*/
	public function skill_view(){
	
	      //$this->writelog_name(var_export($_REQUEST,TRUE),"add_skill_view");	
	
			$ids= I('id')?(int)I('id'):"";
		    if($ids){
			$info = $this->ms->field('id,uid,price,unit,in_id,skill_desc,depth,status,classone,in_name,usex,classone,p_arr,p_num,zpic,is_rz')->find($ids);
			$data['id']=$info['id'];
			$data['skill_id']=(string)$info['id'];
			$data['price']=(string)$info['price'];
			$data['unit']=$info['unit'];			
			$data['pic']= $this->oss_view($this->minfo->where("mid=".$info['uid'])->getField('pic'));
			$data['bgpic']=$this->oss_view($this->minfo->where('mid='.$info['uid'])->getField('bgpic'));
			$data['nickname']= $this->minfo->where("mid=".$info['uid'])->getField('nickname')?$this->minfo->where("mid=".$info['uid'])->getField('nickname'):"";
			$data['Admintype']=$this->retun_leve(M('member')->where("id=".$info['uid'])->getField('Admintype'));
			$data['sex']=(string)$info['usex'];
			$data['age']=$this->birthday(date('Y-m-d',$this->minfo->where('mid='.$info['uid'])->getField('stime')));
			$data['inclass_id']=(string)$info['in_id'];
			$data['depth']=(string)$info['depth'];
			$data['in_name']= $info['in_name'];
			$data['classone']=(string)$info['classone'];	
			$data['classpic'] = M('industry_class')->where("id=".$info['classone'])->getField('pic_path')?__VUPLOAD__.M('industry_class')->where("id=".$info['classone'])->getField('pic_path'):"";
			$data['class_intro'] = M('in_class')->where("id=".$info['in_id'])->getField('class_intro');
			$data['price_t'] =(string)M('in_class')->where("id=".$info['in_id'])->getField('price_t');
			$data['price_d'] =(string)M('in_class')->where("id=".$info['in_id'])->getField('price_d');
			$data['skill_desc']= $info['skill_desc']?$info['skill_desc']:"";
			$data['status']=  $info['status']; 
			$data['addtime']=  date('Y-m-d H:i',$info['addtime']);   //创建时间
			$data['user_id']=$info['uid'];
			$data['is_gz']= M('follow')->where("user_id=".$this->userid." and follow_id=".$info['uid'])->getField('id')?'1':'0';   //是否已经关注
			$data['hx_name'] =  $this->minfo->where("mid=".$info['uid'])->getField('hx_name')?$this->minfo->where("mid=".$info['uid'])->getField('hx_name'):"";   //环信用户名
			 
			if($this->return_check_name($info['p_num'])){
			$data['p_arr']= $info['p_arr']?$this->return_check_name($info['p_arr']).$this->return_check_rate($info['p_rate'])."，".$this->return_check_name($info['p_num']):""; //服务范围
			}else{
			$data['p_arr']= $info['p_arr']?$this->return_check_name($info['p_arr']).$this->return_check_rate($info['p_rate']):""; //服务范围
			}
			$data['p_num']="";  //代接人数
			$data['zpic']=$info['zpic']?$this->oss_view($info['zpic']):""; 
			$data['is_rz']=(string)$info['is_rz']; 
			
			$data['user_type']=(string)$this->mem->where("id=".$info['uid'])->getField('type');    //用户类型 企业用户
			$data['morepic'] =$this->return_morepic_data($ids,1)[0];   //技能图片多图
			$data['morepic_num'] =$this->return_morepic_data($ids,1)[1];   //技能图片多图数量
			if(in_array($data['classone'],array(1,2))){
			$data['is_more']=(string)1; 
			}else{
			$data['is_more']=(string)0; 
			}
			
			
			}else{
			returnApiresult("1","参数为空");exit;
			}
		
			if($data){ 
			returnApiData('0','成功',$data);exit;
			}else{
			returnApiresult("1","失败");exit;
			}
	}
		
	
	/** 2016-4-26
	* Function info: 任务
	*
	*/
	public function task(){
						$table="jdr_task";
						$mapx= (float)I('mapx');//匹配经度
						$mapy= (float)I('mapy'); //匹配经度
						
						
						
						if(I('scity')){ //切换城市	
							if(I('scitycode')){
							$city=I('scitycode');
							$city_code=$this->check_citycode($city);
							}else{
							$city=I('scity');
							$city_code=$this->check_ios_citycode($city);    //IOS
							}
						
						}else{
						
							if(I('citycode')){
							$city=I('citycode');
							$city_code=$this->check_citycode($city);
							}else{
							$city=I('city');
							$city_code=$this->check_ios_citycode($city);    //IOS
							}
						}
						
						
						
						$pageno=I('pageno')?(int)I('pageno'):1;  //第几页
						$pageCount=I('limit')?(int)I('limit'):10;  //每页显示多少条记录录

						$seahot=I('search'); //搜索关键词 
						$classid=I('classid')?(int)I('classid'):"";   //分类查询
						$class_depth=I('depth')?(int)I('depth'):"";   //分类级别
						$orderby=I('orderby'); //排序参数
						$sex=I('sex')?(int)I('sex'):""; 
						$age=I('age');
						$money=I('money'); 
								
				if($city_code){  //定位信息存在						
						$where['where']=array('city'=>$city_code,'status'=>1);  //任务发布
						$where['where']["guoqi_time|guoqi_time"]=array(mgSelect_gt=>time()); //过期或永久查询
						if($seahot){ 
						   if($seahot=="跑腿"){    $where['where']['in_name']= array('$in'=>array("公共交通","私家车","非机动车"));    }else{
						   $where['where']['in_name']= array('$regex'=>$seahot);
						   }
						 } //模糊查询 
						if($orderby==2){
						$where['order']=array('ustime'=>(int)'-1');  //年龄排序 
						}else if($orderby==1){
						$where['order']=array('price'=>(int)'1');    //价格排序 
						}else{
						$where['where']['gps']=array('$nearSphere'=>array($mapx,$mapy));   //默认距离排序
						}
						//******分类查询
						if($classid){   
								if($class_depth==1){
								$where['where']['classone']=$classid; 
								}else{
								$classone=M('industry_class_two')->where("id=".$classid)->getField('parent_id');  //判断是不是一级
								$where['where']['classone']=(int)$classone; 
								
								$classid_arr=M('industry_class_three')->where('parent_id='.$classid)->field('id')->select();	 
									if($classid_arr){
										foreach($classid_arr as $key=>$item){
										$classid_arr2[$key]=(int)$item['id'];
										}  
									    $where['where']['in_id']=array('$in'=>$classid_arr2); 
									}else{
									    $where['where']['in_id']=$classid; 
									}
								}
						} //****分类查询
						//筛选条件
						if($sex==1){ $where['where']['usex']=0;       }
						if($sex==2){ $where['where']['usex']=1;       }
						if($age){    $where['where']['ustime']=$this->return_sx($age,"agem");   }
						if($money){  $where['where']['price']=$this->return_sx($money,"moneym");   }
						//筛选条件  
						$totalRows = count(M_G('task')->select($where));//查询满足要求的总记录数
						$page = ceil($totalRows / $pageCount); //总页数
						$where['page']=$pageno;      //第几页
						$where['limit']=$pageCount;    //每页限制数量
						$task_list=M_G('task')->select($where);
						foreach($task_list as $key=>$item){
						$task[$key]['dis'] = (string)$this->mapdis($item['_id'],$mapx,$mapy,$table);
						$task[$key]['uid'] = (string)$item['uid'];
						$task[$key]['user_id'] = (string)$item['uid'];
						$task[$key]['id'] = (string)$item['id'];
						$task[$key]['status'] =(string)$item['status'];
						$task[$key]['in_id'] = (string)$item['in_id'];
						$task[$key]['classone'] = (string)$item['classone'];
						$task[$key]['classpic'] = M('industry_class')->where("id=".$item['classone'])->getField('pic_path')?__VUPLOAD__.M('industry_class')->where("id=".$item['classone'])->getField('pic_path'):"";
						$task[$key]['in_name'] = $this->mt->where("id=".$item['id'])->getField('in_name');
						$task[$key]['nickname'] = $this->minfo->where("mid=".$item['uid'])->getField('nickname')?$this->minfo->where("mid=".$item['uid'])->getField('nickname'):"";
						$task[$key]['sex'] =(string)$this->minfo->where("mid=".$item['uid'])->getField('sex');
						$task[$key]['pic'] = $this->minfo->where("mid=".$item['uid'])->getField('pic')?$this->oss_view($this->minfo->where("mid=".$item['uid'])->getField('pic')):"";
						$task[$key]['age'] = $this->birthday(date('Y-m-d',$this->minfo->where("mid=".$item['uid'])->getField('stime')));
						$task[$key]['price'] = $this->mt->where("id=".$item['id'])->getField('price');
						$task[$key]['unit'] = $this->mt->where("id=".$item['id'])->getField('unit');
						$task[$key]['task_desc'] = $this->mt->where("id=".$item['id'])->getField('task_desc');
						$task[$key]['user_type']=(string)$this->mem->where("id=".$item['uid'])->getField('type');    //用户类型 企业用户
						if($item['guoqi_time']==0){
						$task[$key]['guoqi'] = '0';   //过期状态  0  1
						$task[$key]['guoqi_time'] = "永久";   //过期时间
						}else{
						$task[$key]['guoqi'] = time()>$item['guoqi_time']?'1':'0';   //过期状态  0  1
						$task[$key]['guoqi_time'] = date("Y-m-d H:i",$item['guoqi_time']);   //过期时间
						}
						}
				
			  }else{		 
						$where['status']=1;    //已发布托管的任务 
						$where['city']=131;  //北京数据
						$where[]=" guoqi_time>".time()." or  guoqi_time=0";  //判断未过期
						
						if($orderby==2){
						$whereorder='ustime desc,addtime desc';  //年龄排序 
						}else if($orderby==1){
						$whereorder='price asc,addtime desc';    //价格排序 
						}else{
						$whereorder='addtime desc';  ////默认排序
						}

						//*****分类查询
						if($classid){   			 	 
							if($class_depth==1){
							$where['classone']=$classid; 
							}else{
							
							$classone=M('industry_class_two')->where("id=".$classid)->getField('parent_id');  //判断是不是一级
							$where['classone']=(int)$classone; 
							
								$classid_arr=M('industry_class_three')->where('parent_id='.$classid)->field('id')->select();
								if($classid_arr){
									foreach($classid_arr as $key=>$item){
									$classid_arr2[$key]=(int)$item['id'];
									}  
									$where[]="in_id in(".implode(",",$classid_arr2).")"; 
								}else{
								     $where['in_id']=$classid;  
								}
							}
						} 
						
						//****分类查询
						
						if($sex==1){   $where['usex']=0;   }
						if($sex==2){   $where['usex']=1;   }
						if($seahot){   $where['in_name']=array('like','%'.$seahot.'%');  }
						
						if($seahot){ 
						   if($seahot=="跑腿"){    $where[]= " in_name in('公共交通','私家车','非机动车')";    }else{
						   $where['in_name']=array('like','%'.$seahot.'%'); 
						   }
						 } 	
						
						if($age){    $where[]=$this->return_sx($age,"age");   }
						if($money){  $where[]=$this->return_sx($money,"money");   }
$task_list= M_S("task")->field('id,uid,price,unit,in_id,in_name,task_desc,depth,status,overday,addtime,classone,guoqi,guoqi_time,usex')->where($where)->order($whereorder)->page($pageno.','.$pageCount)->select();				
						foreach($task_list as $key=>$item){
						$task[$key]['dis'] = "";
						$task[$key]['uid'] = (string)$item['uid'];
						$task[$key]['user_id'] = (string)$item['uid'];
						$task[$key]['id'] = (string)$item['id'];
						$task[$key]['status'] =(string)$item['status'];
						$task[$key]['in_id'] = (string)$item['in_id'];
						$task[$key]['classone'] = (string)$item['classone'];
						$task[$key]['classpic'] = M('industry_class')->where("id=".$item['classone'])->getField('pic_path')?__VUPLOAD__.M('industry_class')->where("id=".$item['classone'])->getField('pic_path'):"";
						$task[$key]['in_name'] = $item['in_name'];
						$task[$key]['nickname'] = $this->minfo->where("mid=".$item['uid'])->getField('nickname')?$this->minfo->where("mid=".$item['uid'])->getField('nickname'):"";
						$task[$key]['sex'] =(string)$this->minfo->where("mid=".$item['uid'])->getField('sex');
						$task[$key]['pic'] = $this->minfo->where("mid=".$item['uid'])->getField('pic')?$this->oss_view($this->minfo->where("mid=".$item['uid'])->getField('pic')):"";
						$task[$key]['age'] = $this->birthday(date('Y-m-d',$this->minfo->where("mid=".$item['uid'])->getField('stime')));
						$task[$key]['price'] = $item['price']?$item['price']:"";
						$task[$key]['unit'] =  $item['unit']?$item['unit']:"";
						$task[$key]['task_desc'] =  $item['task_desc']?$item['task_desc']:"";
						if($item['guoqi_time']==0){
						$task[$key]['guoqi'] = '0';   //过期状态  0  1
						$task[$key]['guoqi_time'] = "永久";   //过期时间
						}else{
						$task[$key]['guoqi'] = time()>$item['guoqi_time']?'1':'0';   //过期状态  0  1
						$task[$key]['guoqi_time'] = date("Y-m-d H:i",$item['guoqi_time']);   //过期时间
						}
						}

						$totalRows = M_S("task")->where($where)->count();//查询满足要求的总记录数
						$page = ceil($totalRows / $pageCount); //总页数
				}
                $task=array_values($task);
				returnApiData_page('0','成功',$page,$task);exit;
	}
	
	
		/** 2016-4-26
	* Function info: 任务详情
	*
	*/
	public function task_view(){

		    $ids= I('id')?(int)I('id'):"";
			
		    if($ids){
			$info = M_S('task')->field('id,uid,price,unit,in_name,in_id,task_desc,status,classone,mapx,mapy,address,number,start_time,end_time,overday,hlong,to_address,to_mapx,to_mapy,addtime,guoqi,guoqi_time,p_arr,p_num,p_rate')->find($ids);
			$data['id']=$info['id'];
			$data['price']=$info['price'];
			$data['unit']=$info['unit']?$info['unit']:"";
			$data['pic']=$this->oss_view($this->minfo->where("mid=".$info['uid'])->getField('pic'));
			$data['bgpic']=$this->oss_view($this->minfo->where('mid='.$info['uid'])->getField('bgpic'));
			$data['nickname']= $this->minfo->where("mid=".$info['uid'])->getField('nickname')?$this->minfo->where("mid=".$info['uid'])->getField('nickname'):"";
			$data['Admintype']= $this->retun_leve(M('member')->where("id=".$info['uid'])->getField('Admintype'));
			$data['sex']= (string)$this->minfo->where("mid=".$info['uid'])->getField('sex');
			$data['age']=$this->birthday(date('Y-m-d',$this->minfo->where('mid='.$info['uid'])->getField('stime')));
			$data['in_name']= $info['in_name']?$info['in_name']:"";
			$data['inclass_id']= $info['in_id']?$info['in_id']:"";
			$data['classpic'] =M('industry_class')->where("id=".$info['classone'])->getField('pic_path')?__VUPLOAD__.M('industry_class')->where("id=".$info['classone'])->getField('pic_path'):"";
			$data['task_desc']=$info['task_desc'];
			$data['guoqi'] = (string)$info['guoqi'];   //过期状态  0  1
		    $data['guoqi_time'] = $info['guoqi_time']==0?"永久":date("Y-m-d H:i",$info['guoqi_time']);   //过期时间
			//$data['start_time'] = $info['start_time']?date('Y-m-d H:i',$info['start_time']):"";   //开始时间
			//$data['end_time'] = $info['guoqi_time']==0?"永久":date("Y-m-d H:i",$info['guoqi_time']);   //过期时间
			$data['classone'] =  $info['classone']?$info['classone']:""; 
			$data['hlong'] =  $info['hlong']?$info['hlong']:"";; 
			$data['address'] = $info['address']?$info['address']:"";   
			$data['mapy'] =  $info['mapy']?$info['mapy']:"";  
			$data['mapx'] =  $info['mapx']?$info['mapx']:""; 
			$data['number'] =  $info['number']?$info['number']:'1';
			$data['to_address'] = $info['to_address']?$info['to_address']:"";     
			$data['to_mapx'] =  $info['to_mapx']?$info['to_mapx']:"";     
			$data['to_mapy'] =  $info['to_mapy']?$info['to_mapy']:"";      
			$data['user_id']=$info['uid'];
		    $data['is_gz'] = M('follow')->where("user_id=".$this->userid." and follow_id=".$info['uid'])->getField('id')?"1":"0";   //是否已经关注
			$data['hx_name'] =  $this->minfo->where("mid=".$info['uid'])->getField('hx_name')?$this->minfo->where("mid=".$info['uid'])->getField('hx_name'):"";   //环信用户名
			if($info['uid']==$this->userid){
			$data['is_bm'] = "1";   //自己发布的任务不可以报名
			}else{
			$data['is_bm'] = M_S('task_item')->where("uid=".$this->userid." and task_id=".$ids)->getField('id')?"1":"0";   //是否已报名
			}
			if($this->return_check_name($info['p_num'])){
			$data['p_arr']= $info['p_arr']?$this->return_check_name($info['p_arr']).$this->return_check_rate($info['p_rate'])."，".$this->return_check_name($info['p_num']):""; //服务范围
			}else{
			$data['p_arr']= $info['p_arr']?$this->return_check_name($info['p_arr']).$this->return_check_rate($info['p_rate']):""; //服务范围
			}
			
			
			$data['p_num']= "";  //代接人数
			$data['user_type']=(string)$this->mem->where("id=".$info['uid'])->getField('type');    //用户类型 企业用户
			
			$data['morepic'] =$this->return_morepic_data_view($ids,2)[0];   //任务图片多图
		    $data['morepic_num'] =$this->return_morepic_data_view($ids,2)[1];   //任务图片多图数量
			
			
			}else{
			returnApiresult("1","参数为空");exit;
			}
			
			if($data){ 
			returnApiData('0','成功',$data);exit;
			}else{
			returnApiresult("1","失败");exit;
			}
	}
		
	public function return_sx($info,$type){   //*******筛选条件两种数据库的查询语句返回
	
		 if($type=='age'){
		 switch ($info){
				case 'a1':
				     $where=" ustime <= 25  and  ustime >=  18";   //    18-15
					break;
				case 'a2':
					 $where=" ustime <= 35  and   ustime > 25";   //    25-35
					break;
				case 'a3':
					 $where=" ustime < 50  and   ustime > 35 ";   //    35-50
					break;
			    case 'a4':
					 $where=" ustime > 50   ";   //   50以上
					break;
			} 
			
         }
			
		if($type=='money'){	
		 
		 switch ($info){
				case 'm1':
				     $where=" price < 100";   //    100以下
					break;
				case 'm2':
					 $where=" price < 500  and  price >=100";   //    100-500
					break;
				case 'm3':
					 $where=" price > 500 ";   //   500以上
					break;
			} 
			
        }
		
		if($type=='agem'){
		 switch ($info){
				case 'a1':
				    // $where=" ustime <= ".strtotime("-18 year")."  and  ustime >=  ".strtotime("-25 year");   //    18-15
					 $where= array('$gte' => strtotime("-25 year"), '$lte' => strtotime("-18 year") );
					break;
				case 'a2':
					// $where=" ustime < ".strtotime("-25 year")."  and   ustime >= ".strtotime("-35 year");   //    25-35
					 $where= array('$gte' => strtotime("-35 year"), '$lt' =>  strtotime("-25 year"));
					break;
				case 'a3':
					// $where=" ustime < ".strtotime("-35 year")."  and   ustime >=  ".strtotime("-50 year");   //    35-50
					 $where= array('$gte' => strtotime("-50 year"), '$lt' =>  strtotime("-35 year"));
					break;
			    case 'a4':
					// $where=" ustime < ".strtotime("-50 year");   //   50以上
					 $where= array('$lt' => strtotime("-50 year"));
					break;
			} 
			
         }
		
	   if($type=='moneym'){	
		 
		 switch ($info){
				case 'm1':
				    // $where=" price < 100";   //    100以下
					 $where= array('$lt' => 100);
					break;
				case 'm2':
					// $where=" price < 500  and  price >=100";   //    100-500
					  $where= array('$lt' => 500, '$gte' => 100);
					break;
				case 'm3':
					 // $where=" price > 500 ";   //   500以上
					  $where= array('$gt' => 500);
					break;
			} 
			
        }
		
			return $where;		
	}
	
	
		public function seahot(){   //*******热词搜索
		
		
           $data=M('search_hot')->field('nickname')->order('list_order desc,id asc')->select();

		   returnApiData('0','成功',$data);exit;
			
			
		}
	
	
		public function search(){   //*******搜索
		
		   $data=$this->ms->field('id,in_name,uid')->order('id desc')->select();
		   
		   returnApiData('0','成功',$data);exit;
			
			
		}
		
		
		public function notice(){    //首页轮播数据
		  $this->writelog_name(var_export($_REQUEST,TRUE),"notice");	
/*				if(I('scity')){ //切换城市
				
				if(I('scitycode')){
				$city=I('scitycode');
				$city_code=$this->check_citycode($city);
				}else{
				$city=I('scity');
				$city_code=$this->check_ios_citycode($city);    //IOS
				}
				
				}else{
				
				if(I('citycode')){
				$city=I('citycode');
				$city_code=$this->check_citycode($city);
				}else{
				$city=I('city');
				$city_code=$this->check_ios_citycode($city);    //IOS
				}
				
				}*/


/*                $tg_data=M('tg_ok_index')->order('addtime desc')->select();
		 
                  
                  foreach ($tg_data as $key => $item){
                      
                     $tg_data[$key]['ts_num']  = $item['ob_num'];
                     for($i = 1; $i<=$tg_data[$key]['ts_num']; $i++){
                         
                        $ts_list[] = $item;
                            
                        }
                      
                   }
           
         
      
                 foreach ($ts_list as $key1 => $item1){
                   if( $item['ob_type'] == 1 ){
                       if($this->ms->where('id='.$item1['ob_id'])->getField('in_name')){             
                     $ts_list[$key1]['in_name']  =  $this->ms->where('id='.$item1['ob_id'])->getField('in_name');
                     $ts_list[$key1]['nickname'] = $this->minfo->where('mid='.$ts_list[$key1]['user_id'])->getField('nickname');
                     $data1[$key1]['nickname'] =   $ts_list[$key1]['nickname'];
                     $data[$key1]['info'] = '"'.$data1[$key1]['nickname']. '" 发布了技能：' .$ts_list[$key1]['in_name'];
					  $data[$key1]['ob_name'] = $ts_list[$key1]['in_name'];
					  $data[$key1]['ob_type'] = $item['ob_type'];
					  $data[$key1]['id'] = $item1['ob_id'];
                       }
                    } else {
					  if($this->mt->where('id='.$item1['ob_id'])->getField('in_name')){ 
                     $ts_list[$key1]['in_name']  =  $this->mt->where('id='.$item1['ob_id'])->getField('in_name');
                     $ts_list[$key1]['nickname'] = $this->minfo->where('mid='.$ts_list[$key1]['user_id'])->getField('nickname');
                     $data1[$key1]['nickname'] =   $ts_list[$key1]['nickname'];
                     $data[$key1]['info'] = '"'.$data1[$key1]['nickname']. '" 发布了任务：' .$ts_list[$key1]['in_name'];
					  $data[$key1]['ob_name'] = $ts_list[$key1]['in_name'];
					  $data[$key1]['ob_type'] = $item['ob_type'];
					  $data[$key1]['id'] = $item1['ob_id'];
					   }
                    }
                    
                 }
				 if($data){
				 $data=array_values($data);
				 }*/
				 
				
				 
				 if(empty($data)){  
				 
				   $num="10";
				   $skill_data= $this->ms->field('id,uid,in_id,in_name,addtime')->where("status=0 and city=58")->order('addtime desc' )->limit($num)->select();   
				     foreach ($skill_data as $key => $item){ 
					 		 $nickname=$this->minfo->where('mid='.$item['uid'])->getField('nickname');
					  	if($this->utf8_strlen($nickname)>8){  $nickname=mb_substr($nickname,0,8,'utf-8')."...";  }
						$s_data[$key]['info'] = '"'.$nickname. '" 发布了技能&' .$item['in_name'];
						$s_data[$key]['ob_name'] = $item['in_name'];
						$s_data[$key]['ob_type'] = 1;
						$s_data[$key]['id'] = $item['id'];
						$s_data[$key]['user_id'] = $item['uid'];
						$s_data[$key]['addtime'] = $item['addtime'];
					 }                  
				   $task_data= $this->mt->field('id,uid,in_id,in_name,addtime')->where("status=1 and city=58")->order('addtime desc' )->limit($num)->select();  
				   	  foreach ($task_data as $key => $item){ 
					  
					   $nickname=$this->minfo->where('mid='.$item['uid'])->getField('nickname');
					  	if($this->utf8_strlen($nickname)>8){  $nickname=mb_substr($nickname,0,8,'utf-8')."...";  }
						
						$t_data[$key]['info'] = '"'.$nickname. '" 发布了任务&' .$item['in_name'];
						$t_data[$key]['ob_name'] = $item['in_name'];
						$t_data[$key]['ob_type'] = 2;
						$t_data[$key]['id'] = $item['id'];
						$t_data[$key]['user_id'] = $item['uid'];
						$t_data[$key]['addtime'] = $item['addtime'];
					 } 
					 
					 $data = array_merge($s_data,$t_data);  //合并技能和任务查询数组
					 	  foreach ($data as $key => $item){ 
						     $datetime[] = $item['addtime'];
						  }
						  
					 array_multisort($datetime,SORT_DESC,$data);
					// print_r($data);exit;
				   }
				 
				 
				 
				// print_r($data);exit;
				 
				// $data_ok[$key]['info']=$data;

		   returnApiData('0','成功',$data?$data:array());exit;
			
			
		}
	
	
	
}